/**
  ******************************************************************************
  * @file    Project/Bsp/menu.h 
  * @author  zlf
  * @version V1.0.0
  * @date    2016-04-05
  * @brief   Header for menu.c module
  *****************************************************************************
  */

/* Define to prevent recursive inclusion -------------------------------------*/

#ifndef __MENU_H
#define __MENU_H

/* Includes ------------------------------------------------------------------*/
#include <string.h>
#include "main.h"
#include "menuId.h"

/* Exported macro ------------------------------------------------------------*/
#define MENU_ITEM_NUM_MAX						( 6 )//5

#define MENU_DIGIT_THOU_POS						( 60 ) //64
#define MENU_DIGIT_HUND_POS						( MENU_DIGIT_THOU_POS+8 )
#define MENU_DIGIT_DECI_POS						( MENU_DIGIT_THOU_POS+16 )
#define MENU_DIGIT_INDI_POS						( MENU_DIGIT_THOU_POS+24 )
#define MENU_DIGIT_UINT_POS						( MENU_DIGIT_THOU_POS+32 )

#define MENU_LINE_ONE							( 0 )
#define MENU_LINE_TWO							( 16 )
#define MENU_LINE_THREE						( 32 )
#define MENU_LINE_FOUR						( 48 )

#define MENU_BAR_POSITION					( 20 )
#define MENU_ORIGIN								( 0 )
#define MENU_PIXAL								( 127 )
#define MENU_PIXAL_T							( 88 )
#define MENU_PIXAL_E							( 87 )
#define MENU_STYLE_POS						( 32 )


/* Exported types ------------------------------------------------------------*/
//define the menu structure
typedef struct Menu
{
	//the ID of frame, unanimity with the index of menu
	u8 FrameID; 
	//initialise the menu parameter
	void (*MenuInit)(void);
	//update the parameter
	void (*UpdateParam)(void);
	//call when key is pressed
	void (*FrameKeyDown)(u8 Key);
	//call when key is released
	void (*FrameKeyUp)(u8 Key);
}Menu;

//define the language kind, only support Chinese and English right now
typedef enum
{
	GERMAN  = 0x00,
	ENGLISH = 0x01,
	CHINESE = 0x02,
	LANGNUM = 0x02
}Language_TypeDef;
//define the menu related parameter
typedef struct MenuPara
{
	//current ID of frame
	u8 CurFrameID;
	//record the key value last time
	u8 LastKey;
	//record the language selected
	Language_TypeDef Language;
}Menu_Para;

//define the bar menu structure
typedef struct BarMenu
{
	//current Item where be highlighted
	vu8 Where;
	//the number of items where the menu of this layer included
	vu8 ItemNum;
	//the position last time when bar menu initials for 3 layers
	vu8 LastPosition[MENU_ITEM_NUM_MAX]; 		
	//the pointer to the tip to be displayed
	uc8 **TitleItem;
	//the pointer to the content to be displayed
	uc8 **DispItem;
}BarMenu;

//define the state of digit setting
typedef enum
{
	STATE_HUNDRED_SETTING = 0,
	STATE_DECIMAL_SETTING = 1,
	STATE_INDIVIDUAL_SETTING = 2
}STATE_DIGIT_SETTING;

//define the structure of digit setting menu
typedef struct DigitSetMenu
{
	//the state of digit setting
	STATE_DIGIT_SETTING DigitSettingIndex;
	//the digit num
	STATE_DIGIT_SETTING DigitSettingNum;
	//the hundred digit number, 0~9
	u8 HundDigit;
	//the upper limit of hundred digit
	u8 HundUpperLimit;
	//the lower limit of hundred digit
	u8 HundLowerLimit;
	//the decimal digit number, 0~9
	u8 DeciDigit;
	//the upper limit of decimal digit
	u8 DeciUpperLimit;
	//the lower limit of decimal digit
	u8 DeciLowerLimit;
	//the individual digit number, 0~9
	u8 IndiDigit;
	//the upper limit of individual digit
	u8 IndiUpperLimit;
	//the lower limit of individual digit
	u8 IndiLowerLimit;
}DigitSetMenu;

typedef struct TimeSet
{
	u8  Time_Index;
	u8  Time_Year_H;
	u8  Time_Year_L;
	u8  Time_Month_H;
	u8  Time_Month_L;
	u8  Time_Day_H;
	u8  Time_Day_L;
	u8  Time_Hour_H;
	u8  Time_Hour_L;
	u8  Time_Minute_H;
	u8  Time_Minute_L;
	u8  Time_Second_H;
	u8  Time_Second_L;
	u8  Time_Week;
}TimeSet;

/* Exported variables --------------------------------------------------------*/
extern Menu_Para Global_Menu_Para;
extern BarMenu Bar_Menu_Para;
extern DigitSetMenu Digit_Set_Menu_Para;
extern TimeSet Time_Set_Para;

/* Exported functions --------------------------------------------------------*/
extern void Menu_Init( void );

extern void BarMenuInit( void );
extern void BarMenuDown( void );
extern void BarMenuUp( void );

extern void DigitSetMenuInit( void );
extern void DigitSetMenuDown( void );
extern void DigitSetMenuUp( void );

extern void FrameManagement( void );
extern void JumpFrame( u8 frameID );

#endif /* __MENU_H */
 

